package com.yehui.jdk.jdk11;

import java.util.Objects;

/**
 * @author 业徽
 * @date 2021/8/23
 */
public class StringDemo {

    public static void main(String[] args) {
        trimAndTrip();
        isBlank();

        System.out.println("lines: " + "a\na\na\n".lines().count());
        System.out.println("repeat: " + "afdfs".repeat(4));
    }

    private static void trimAndTrip() {
        String normalEmpty = " ffdfsdfsfsfs ";
        String unicodeEmpty = "\u2000ffdfsdfsfsfs\u2000";
        System.out.println("normalEmpty.trim().length(): " + normalEmpty.trim().length());
        System.out.println("unicodeEmpty.trim().length(): " + unicodeEmpty.trim().length());
        System.out.println("Objects.equals(normalEmpty.trim(), unicodeEmpty.trim()): " + Objects.equals(normalEmpty.trim(), unicodeEmpty.trim()));
        System.out.println("normalEmpty.strip().length(): " + normalEmpty.strip().length());
        System.out.println("unicodeEmpty.strip().length(): " + unicodeEmpty.strip().length());
        System.out.println("Objects.equals(normalEmpty.strip(), unicodeEmpty.strip()): " + Objects.equals(normalEmpty.strip(), unicodeEmpty.strip()));

        System.out.println("unicodeEmpty.stripLeading(): " + unicodeEmpty.stripLeading());
        System.out.println("unicodeEmpty.stripTrailing(): " + unicodeEmpty.stripTrailing());
    }

    private static void isBlank() {
        System.out.println("\"\".isBlank(): " + "".isBlank());
        System.out.println("\"\".isEmpty(): " + "".isEmpty());
        System.out.println("\"    \".isBlank(): " + "    ".isBlank());
        System.out.println("\"    \".isEmpty(): " + "    ".isEmpty());
        System.out.println("\"\\u2000\\u2000\".isBlank(): " + "\u2000\u2000".isBlank());
        System.out.println("\"\\u2000\\u2000\".isEmpty(): " + "\u2000\u2000".isEmpty());

        String a = null;
        try {
            System.out.println("a.isBlank(): " + a.isBlank());
        } catch (Exception e) {
            System.out.println("String a = null;a.isBlank(); throw: " + e);
        }
    }

}
